package com.vlin.scene.actuator.defaut;

import java.util.ArrayList;
import java.util.List;

import com.vlin.entity.scene.Command;
import com.vlin.scene.actuator.AbstractCommandHandler;
import com.vlin.scene.actuator.CommandHandler;
import com.vlin.scene.actuator.ListCommandHandler;

public class DefaultListCommandHandler extends AbstractCommandHandler implements ListCommandHandler {
	
	private List<CommandHandler> listHandler = new ArrayList<CommandHandler>();

	@Override
	public void addCommandHandler(CommandHandler commandHandler) {
		
		if(commandHandler != null) {
			this.listHandler.add(commandHandler);
		}
		
		
	}

	@Override
	public boolean doSupport(Command command) {
		
		for(CommandHandler commandHandler : listHandler) {
			if(commandHandler.support(command)) {
				return true;
			}
		}
		
		return false;
	}

	@Override
	public void doHandle(Command command) {
		for(CommandHandler commandHandler : listHandler) {
			if(commandHandler.support(command)) {
				commandHandler.handle(command);
			}
		}
	}

}
